package com.dev.demo;

/**
 * @description:
 * @className: ConfigurableStrategyDemo
 * @package: com.dev.demo
 * @author: yangzhi@hsyuntai.com
 * @date: 2019-04-13 15:23
 * @copyright: 版权归 HSYUNTAI 所有
 */

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class ConfigurableStrategyDemo {

    public static IService createService(String key) {
        try {
            InputStream in = new BufferedInputStream(new FileInputStream("/Users/yangzhi/IdeaProjects/git/code/out/production/code/resource/config.properties"));
            Properties p = new Properties();
            p.load(in);
            String className = p.getProperty(key);
            Class<?> cls = Class.forName(className);
            return (IService) cls.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        IService service = createService("serviceA");
        service.action();
        System.out.println("****************");
        service = createService("serviceB");
        service.action();
    }

}